home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / grunda.exe / GRUNDA.C < prev    next >
C/C++ Source or Header  |  1991-05-31  |  8KB  |  423 lines

  1. /***********************************************************\
  2. *                   Joe Walsh Presents:                     *
  3. *                                                           *
  4. *                       Grunda IBM                          *
  5. *                                                           *
  6. *    Grunda is freeware, and in the public domain.          *
  7. *                                                           *
  8. *                                Last Update: 05/31/91      *
  9. \***********************************************************/
  10.  
  11. #include "joy.h"
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <conio.h>
  15. #include <dos.h>
  16.  
  17. #define H '\x02'   /* The Human's Icon...a happy face */
  18. #define G '\x0C'   /* Grunda's Icon */
  19. #define W '\xDB'   /* The Wall Character */
  20. #define L '\xFB'   /* The Lever Character */
  21. #define K '\xEC'   /* The Security Pass Character */
  22.  
  23. char e=0;          /* End Game Flag Variable */
  24. char button=0;     /* Button 1 Variable */
  25. char buttonb=0;    /* Button 2 Variable */
  26. char level=0;      /* Level Currently Being Played (0-9) */
  27. char dont=0;       /* Game Opening Avoidance Variable */
  28. char w=0;          /* Player Won Flag Variable */
  29. char c=0;          /* Getch Storage Variable */
  30. char pass=0;       /* Security Pass Variable */
  31. char echs=0;       /* pass x value */
  32. char why=0;        /* pass y value */
  33. char a=0;          /* grunda's x value/location */
  34. char b=0;          /* grunda's y value/location */
  35. char am=0;         /* grunda's proposed x movement */
  36. char bm=0;         /* grunda's proposed y movement */
  37. char x=0;          /* human's x value/location */
  38. char y=0;          /* human's y value/location */
  39. char wx=0;         /* lever's x value/location */
  40. char wy=0;         /* lever's y value/location */
  41. char xm=0;         /* human's proposed x movement */
  42. char ym=0;         /* human's proposed y movement */
  43. int keymin=0;      /* the minimum y value recorded on the joystick */
  44. int keymax=0;      /* the maximum y value recorded on the joystick */
  45. int joymin=0;      /* the minimum x value recorded on the joystick */
  46. int joymax=0;      /* the maximum x value recorded on the joystick */
  47. int joy=0;         /* the joystick's x value read at the current time */
  48. int key=0;         /* the joystick's y value read at the current time */
  49. int snd=0;         /* Sound Variable */
  50. int p=0;           /* counter variable for wait loop */
  51.  
  52. main(void)
  53. {
  54.     randomize();
  55.     _setcursortype(_NOCURSOR);
  56.     if (dont==0)
  57.     {
  58.         title();
  59.         center();
  60.    }
  61.     draw();
  62.     while ((e != 1) && (w!=1))
  63.     {
  64.         game();
  65.     }
  66.     if (e!=1){
  67.     gotoxy(10,10);
  68.      puts("You Won!!!!!");
  69.     }
  70.     do {
  71.     button=get_joy_button(0);
  72.    buttonb=get_joy_button(1);
  73.       } while ((button!=1) && (buttonb!=1));
  74.     if (buttonb==1)
  75.     {
  76.         e=0;
  77.       dont=1;
  78.         level=0;
  79.         pass=0;
  80.         w=0;
  81.         main();
  82.     }
  83.     if (button==1)
  84.    {
  85.         _setcursortype(_NORMALCURSOR);
  86.         clrscr();
  87.       nosound();
  88.         exit(0);
  89.    }
  90.    return 0;
  91. }
  92.  
  93. title(void)
  94. {
  95.     clrscr();
  96.     gotoxy(35, 10);
  97.     puts("Grunda");
  98.     gotoxy(32, 12);
  99.     puts("By Joe Walsh");
  100.     gotoxy(1,24);
  101.      puts("Press Button To Begin Game");
  102.     do {
  103.     button=get_joy_button(0);
  104.     } while (button!=1);
  105.     button=0;
  106.    return;
  107. }
  108.  
  109. center(void)
  110. {
  111.     clrscr();
  112.     gotoxy(10,10);
  113.     puts("Would you like sound? (Y/N)");
  114.     while (snd==0) 
  115.     {
  116.         c=getch();
  117.         if (c=='\0')
  118.       {
  119.             c=getch();
  120.       }
  121.         switch(c)
  122.       {
  123.             case 89: snd=1;
  124.                         break;
  125.             case 121: snd=1;
  126.                         break;
  127.             case 78: snd=2;
  128.                         break;
  129.             case 110: snd=2;
  130.                         break;
  131.             default: putchar('\a');
  132.         }
  133.     }
  134.     gotoxy(10,12);
  135.     puts("Put Stick in Upper Left Corner, Then Press Button.");
  136.     do {
  137.         keymin=get_joy_position(1);
  138.         joymin=get_joy_position(0);
  139.         button=get_joy_button(0);
  140.     }while (button!=1);
  141.     button=0;
  142.    delay(400);
  143.     gotoxy(10,14);
  144.     puts("Put Stick in Lower Right Corner, Then Press Button.");
  145.     do {
  146.         keymax=get_joy_position(1);
  147.         joymax=get_joy_position(0);
  148.         button=get_joy_button(0);
  149.     }while (button!=1);
  150.    delay(400);
  151.     return;
  152. }
  153. draw(void)
  154. {
  155.     clrscr();
  156.     for (wx=0; wx<79; wx++) {
  157.          gotoxy(wx,0);
  158.          putchar(W);
  159.     }
  160.     for (wx=0; wx<81; wx++) {
  161.         gotoxy(wx,24);
  162.         putchar(W);
  163.     }
  164.     for (wy=3; wy<23; wy++) {
  165.         gotoxy(5,wy);
  166.         putchar(W);
  167.     }
  168.     for (wy=3; wy<23; wy++) {
  169.         gotoxy(76,wy);
  170.         putchar(W);
  171.     }
  172.     gotoxy(76,23);
  173.     putchar(G);
  174.     gotoxy(4,13);
  175.     putchar(H);
  176.     gotoxy(40,13);
  177.     printf("%d", level);
  178.     echs=random(60);
  179.     why=random(20);
  180.     echs=echs+10;
  181.     why=why+2;
  182.     if ((echs == 40) && (why == 13))
  183.     {
  184.         echs=echs+1;
  185.       why=why+1;
  186.     }
  187.     gotoxy(echs,why);
  188.     putchar(K);
  189.     x = 4;
  190.     y = 13;
  191.     a = 76;
  192.     b = 23;
  193.    return;
  194. }
  195.  
  196. game(void)
  197. {
  198.     key = get_joy_position(1);
  199.     joy = get_joy_position(0);
  200.     if (snd == 1)
  201.     {
  202.         sound(random(100)+(key+joy));
  203.     }
  204.         if (key<(keymin+12)){
  205.              ym=-1;
  206.         }
  207.         if (key>(keymax-12)) {
  208.             ym=1;
  209.         }
  210.         if (joy>(joymax-12)) {
  211.             xm=1;
  212.         }
  213.         if (joy<(joymin+12)) {
  214.             xm=-1;
  215.              }
  216.     moveh();
  217.      moveg();
  218.     if ((x==a) && (y==b)) {
  219.         end();
  220.     }
  221.      return;
  222. }
  223.  
  224. moveh(void)              /* Human Movement Phase */
  225. {
  226.     gotoxy(x,y);
  227.     putchar(' ');
  228.     x = x + xm;
  229.     y = y + ym;
  230.     if (x > 79) 
  231.     {
  232.         if ((level!=9) && (pass==1))
  233.         {
  234.             x=1;
  235.             level++;
  236.             gotoxy(40,13);
  237.             printf("%d", level);
  238.             if (level==9)
  239.             {
  240.                 gotoxy(60,13);
  241.                 putchar(L);
  242.             }
  243.             else
  244.             {
  245.                 echs=random(60);
  246.                 why=random(20);
  247.                 echs=echs+10;
  248.                 why=why+2;
  249.                 if (echs==40)
  250.                 {
  251.                     echs=echs+1;
  252.                 }
  253.                 if (why==13)
  254.                 {
  255.                     why=why+1;
  256.                 }
  257.                 gotoxy(echs,why);
  258.                 putchar(K);
  259.                 pass=0;
  260.             } 
  261.         }
  262.         else
  263.         {
  264.             x=79;
  265.         }
  266.     }
  267.     if (x < 01) {
  268.         x=1;}
  269.     if (y < 02) {
  270.         y=2;}
  271.     if (y > 23) {
  272.         y = 23;}
  273.     if (x == 5) {
  274.         if ((y != 2) && (y != 23)){
  275.             x = x - xm;
  276.             y = y - ym;}
  277.     }
  278.     if (x == 76) {
  279.         if ((y != 2) && (y != 23)){
  280.             x = x - xm;
  281.             y = y - ym;}
  282.     }
  283.     if ((x == 40) && (y == 13)){
  284.         x = x - xm;
  285.              y = y - ym;}
  286.     if (level == 9)
  287.     {
  288.         if ((x == 60) && (y == 13))
  289.         {
  290.             w=1;
  291.         }
  292.     }
  293.     if (pass==0)
  294.     {
  295.         if ((x == echs) && (y == why))
  296.         {
  297.             pass=1;
  298.         }
  299.    }
  300.     ym = 0;
  301.     xm = 0;
  302.     gotoxy(x,y);
  303.     putchar(H);
  304.     return;
  305. }
  306.  
  307. moveg(void)                         /* Grunda's Movement Phase */
  308. {
  309.     gotoxy(a,b);
  310.    delay(20);
  311.     putchar(' ');
  312.     p=random(100+((10-level)*(3)));
  313.     if ((a < x) && (p<=80)){
  314.         am = 1; }
  315.     if ((a > x) && (p<=80)){
  316.         am = -1; }
  317.     if ((b < y) && (p<=80)){
  318.         bm = 1; }
  319.     if ((b > y) && (p<=80)){
  320.         bm = -1; }
  321.     a = a + am;
  322.     b = b + bm;
  323.     if (a > 79) {
  324.         a=79;}
  325.     if (a < 01) {
  326.         a=1;}
  327.     if (b < 02) {
  328.         b=2;}
  329.     if (b > 23) {
  330.         b = 23;}
  331.     if (a == 5) {
  332.         if ((b != 2) && (b != 23)){
  333.             a = a - am;}
  334.         if (b==22) 
  335.         {
  336.             b=23;
  337.         }
  338.         if (b==3)
  339.         {
  340.             b=2;
  341.         }
  342.     }
  343.     if (a == 76) {
  344.         if ((b != 2) && (b != 23)){
  345.             a = a - am;}
  346.         if (b==22)
  347.         {
  348.             b=23;
  349.         }
  350.         if (b==3)
  351.         {
  352.             b=2;
  353.         }
  354.     }
  355.     if ((a == 40) && (b == 13)){
  356.              a = a - am;
  357.              b = b - bm;}
  358.     if (level==9)
  359.     {
  360.         if ((a==60) && (b == 13))
  361.         {
  362.             a=a-am;
  363.             b=b-bm;
  364.         }
  365.    }
  366.     if (pass==0)
  367.     {
  368.         if ((a == echs) && (b == why))
  369.         {
  370.             a=a-am;
  371.          b=b-bm;
  372.         }
  373.    }
  374.     am = 0;
  375.     bm = 0;
  376.     gotoxy(a,b);
  377.     putchar(G);
  378.     return;
  379. }
  380.  
  381. end(void)
  382. {
  383.     nosound();
  384.     gotoxy(x,y);
  385.     puts("*");
  386.     for (p=0;p<4;p++)
  387.     {
  388.         gotoxy(x+p,y);
  389.         puts("*");
  390.         gotoxy(x-p,y);
  391.         puts("*");
  392.         gotoxy(x,y);
  393.         puts("*");
  394.         gotoxy(x+p,y-p);
  395.         puts("*");
  396.         gotoxy(x-p,y-p);
  397.         puts("*");
  398.         gotoxy(x,y-p);
  399.         puts("*");
  400.         gotoxy(x+p,y+p);
  401.         puts("*");
  402.         gotoxy(x-p,y+p);
  403.         puts("*");
  404.         gotoxy(x,y+p);
  405.         puts("*");
  406.         if ((y+p+1)>24)
  407.               p=4;
  408.     }
  409.     if (snd == 1)
  410.     {
  411.         for (p=0;p<6000;p++)
  412.         {
  413.             sound(random(200));
  414.         }
  415.    }
  416.     gotoxy(10,10);
  417.     puts("Press button 1 to end game.");
  418.     gotoxy(10,12);
  419.     puts("Press button 2 to begin a new game.");
  420.    nosound();
  421.     e = 1;
  422.     return;
  423. }